package com.fr.report.script.function;

import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;

public class ODD extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    if (paramArrayOfObject.length < 1)
      return Primitive.ERROR_NAME;
    Object localObject = null;
    for (int i = 0; i < paramArrayOfObject.length; ++i)
    {
      localObject = paramArrayOfObject[i];
      if (localObject instanceof Number)
      {
        if ((localObject instanceof Long) && (Math.abs(((Number)localObject).longValue() % 2L) == 1L))
          return new Long(((Number)localObject).longValue());
        double d = ((Number)localObject).doubleValue();
        long l = ()d % 2L;
        if (d > 0.0D)
        {
          if (l == 0L)
            return new Long(()d + 1L);
          return new Long(()d + 2L);
        }
        if (l == 0L)
          return new Long(()d - 1L);
        return new Long(()d - 2L);
      }
    }
    return new Integer(0);
  }

  public Function.Type getType()
  {
    return Function.MATH;
  }

  public String getCN()
  {
    return "ODD(number):返回对指定数值进行舍入后的奇数。\nnumber:是要舍入求奇的数值。\n不论正负号如何，数值都朝着远离 0 的方向舍入。如果 number 恰好是奇数，则不须进行任何舍入处理。\n示例:\nODD(1.5) 等于 3\nODD(3) 等于 3\nODD(2) 等于 3\nODD(-1) 等于 -1";
  }

  public String getEN()
  {
    return "ODD(number): Returns number rounded up to the nearest odd integer.\nNumber is the value to round.\nRegardless of the sign of number, a value is rounded up when adjusted away from zero. If number is an odd integer, no rounding occurs. \n\nExample:\n   ODD(1.5) = 3\n   ODD(3) = 3\n   ODD(2) = 3\n   ODD(-1) = -1";
  }
}